#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t pid = fork();
    if (pid > 0)
    {
        // father
        printf("i am father, i am waiting!\n");
        int status = -1;
        pid_t ret = wait(&status);
        printf("wait succeed! pid: %d\n", ret);
        if (WIFEXITED(status))
        {
            printf("exit code: %d\n", (status >> 8)& 0xff);
        }
    }
    else if (pid == 0)
    {
        // child
        printf("i am child, pid: %d, ppid: %d\n", getpid(), getppid());
        sleep(3);
    }
    else 
    {
        perror("fork error");
    }
    return 0;
}
